<%@page import="java.util.Date" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/head.jsp" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>公文共享页面</span>
    </div>
    <!--用户-->
    <table class="providerTable" cellpadding="0" cellspacing="0">
        <tr class="firstTr">
            <th width="10%">发件人</th>
            <th width="10%">收件人</th>
            <th width="20%">主题</th>
            <th width="10%">文件名</th>
            <th width="10%">文件密级</th>
            <th width="10%">时间</th>
            <th width="20%">操作</th>
        </tr>
        <c:forEach var="doc" items="${documents }" varStatus="status">
            <tr>
                <td>
                    <span>${doc.sendUser}</span>
                </td>
                <td>
                    <span>${doc.receiveUser}</span>
                </td>
                <td>
                    <span>${doc.title}</span>
                </td>
                <td>
                    <span>${doc.fileName}</span>
                </td>
                <td>
                    <c:choose>
                        <c:when test="${doc.fileLevel == 0 }">
                            <span>普通</span>
                        </c:when>
                        <c:when test="${doc.fileLevel == 1 }">
                            <span>秘密</span>
                        </c:when>
                        <c:when test="${doc.fileLevel == 2 }">
                            <span>机密</span>
                        </c:when>
                        <c:otherwise>
                            <span>绝密</span>
                        </c:otherwise>
                    </c:choose>
                </td>
                <td>
                    <span>${doc.time}</span>
                </td>
                <td>
                    <span><a class="downDocument" docid=${doc.id } filepath=${doc.filePath }>下载</a></span>
                    <c:if test="${user.level == '绝密级' }">
                        &nbsp;&nbsp;&nbsp;
                        <span><a class="deleteDocument" docid=${doc.id }>删除</a></span>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
</section>

<div class="zhezhao"></div>
<div class="remove" id="removeProv">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain" >
            <p>你确定要删除该公文吗？</p>
            <a href="#" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>

<%@include file="/WEB-INF/jsp/common/foot.jsp" %>

<script>
    var documentObj;

    function deleteDocument(obj){
        window.location.href="/eDocTrans/delete?id="+ obj.attr("docid");
    }
    function openYesOrNoDLG(){
        $('.zhezhao').css('display', 'block');
        $('#removeProv').fadeIn();
    }

    function cancleBtn(){
        $('.zhezhao').css('display', 'none');
        $('#removeProv').fadeOut();
    }
    function changeDLGContent(contentStr){
        var p = $(".removeMain").find("p");
        p.html(contentStr);
    }

    $(function() {
        $(".downDocument").on("click", function () {
            //将被绑定的元素（a）转换成jquery对象，可以使用jquery方法
            var obj = $(this);
            window.open("/eDocTrans/down?file=" + obj.attr("filepath"), "_blank");
        });

        $('#no').click(function () {
            cancleBtn();
        });

        $('#yes').click(function () {
            deleteDocument(documentObj);
        });

        $(".deleteDocument").on("click",function(){
            documentObj = $(this);
            changeDLGContent("你确定要删除此公文吗？");
            openYesOrNoDLG();
        });
    });

</script>
